import re
from typing import List


class Solution:
    def calculate(self, calculate_type):
        if calculate_type == '+':
            return lambda a, b: a + b
        elif calculate_type == '-':
            return lambda a, b: a - b
        elif calculate_type == '*':
            return lambda a, b: a * b
        elif calculate_type == '/':
            return lambda a, b: a / b
        print(calculate_type)
        raise Exception('<UNK>')
    @staticmethod
    def is_integer(s):
        return bool(re.fullmatch(r'^[-+]?\d+$', s))
    def evalRPN(self, tokens: List[str]) -> int:
       st = []

       for token in tokens:
           # 纯数字,包含负数
           if self.is_integer(token):
               st.append(int(token))
           else:
               if not st:
                   raise Exception('<UNK>')
               cal_func = self.calculate(token)
               # 顺序不能错
               b = st.pop()
               a = st.pop()
               result = cal_func(a,b)
               st.append(int(result))
       return int(st.pop())

print(Solution().evalRPN(["10","6","9","3","+","-11","*","/","*","17","+","5","+"]))
from operator import add, sub, mul
